package com.huang.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huang.vo.Pager;

import java.util.Map;
import java.util.Optional;

/**
 * @author han
 * @since 2022-02-11 14:47:50
 */
public class BaseController {

    protected Pager<?> parse(Pager<?> pager, QueryWrapper<?> queryWrapper) {
        pager = Optional.ofNullable(pager).orElse(new Pager<>());
        Map<String, Object> detailMap = pager.getDetailMap();
        detailMap.entrySet().stream()
                .filter(e -> null != e.getValue())
                .forEach(e-> queryWrapper.eq(e.getKey(), e.getValue()));

        Map<String, Object> likeMap = pager.getLikeMap();
        likeMap.entrySet().stream()
                .filter(e -> null != e.getValue())
                .forEach(e-> queryWrapper.like(e.getKey(), e.getValue()));
        return pager;
    }
}
